import { defineStore } from "pinia";
import { ref } from "vue";
import { getTopicListService, getTopicRankService } from "@/api/topic";

export const useTopicStore = defineStore("topic", () => {
  //    Topic {
  //     private Integer id;     //话题id
  //     private String topicName;  //话题名称
  //     private int topicType;    //话题类型，对应喜好
  //     private Integer topicHot;   //话题热度，由下面两个决定
  //     private Integer topicSpeeches;  //话题发言数
  //     private Integer topicLikes; //话题点赞数
  //     private Integer topicFromId;    //话题发布人id
  // }
  // 用于话题的展示
  const topicList = ref([]);
  // 话题热度的排行榜
  const topicRank = ref([]);
  //
  const topic = ref({});

  //添加话题展示
  const setTopicList = async () => {
    const res = await getTopicListService();
    topicList.value = res.data;
  };

  // 添加话题的前10排行榜
  const setTopicRank = async () => {
    const res = await getTopicRankService();
    topicRank.value = res.data;
  };

  return {
    topicList,
    topicRank,
    topic,
    setTopicList,
    setTopicRank,
  };
});
